//
//  yxpPulldownVC.m
//  TestProject
//
//  Created by 杨小平 on 14-8-26.
//  Copyright (c) 2014年 yangxiaoping. All rights reserved.
//

#import "yxpPulldownVC.h"
#import "yxpPulldownList.h"

@interface yxpPulldownVC ()<yxpPulldownListDataSource,yxpPulldownListDelegate>
{
    yxpPulldownList *_pulldownList;
    NSMutableArray *_chooseArray ;
}



@end

@implementation yxpPulldownVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    [self initData];
    
    //加载下拉视图
    _pulldownList=[[yxpPulldownList alloc] initWithFrame:CGRectMake(0, 65, 320, 40) dataSource:self delegate:self superView:self.view];
}
- (void)initData
{
    NSMutableArray *section1=[[NSMutableArray alloc] initWithCapacity:0];
    [section1 addObject:@{@"主城区":@[@"南岸区",@"沙坪坝区",@"渝中区"]}];
    [section1 addObject:@{@"北部区":@[@"江北区",@"北部新区",@"大渡口区"]}];
    [section1 addObject:@{@"副城区":@[@"大渡口区",@"万州区"]}];

    NSMutableArray *section2=[[NSMutableArray alloc] initWithCapacity:0];
    [section2 addObject:@{@"color":@[@"red",@"blue",@"yellow",@"black"]}];
    [section2 addObject:@{@"黄色":@[@"香蕉",@"橘子",@"柚子"]}];
    [section2 addObject:@{@"其他":@[@"火龙果",@"葡萄",@"荔枝",@"杨桃"]}];
    [section2 addObject:@{@"绿色":@[@"苹果",@"梨子",@"西瓜"]}];
    
    _chooseArray=[@[section1,section2] mutableCopy];
}
#pragma mark --yxpPulldownListDelegate,yxpPulldownListDataSource
- (void)chooseAtSection:(NSInteger)section index:(NSInteger)index titleIndex:(NSInteger)titleindex
{
    NSDictionary *dic=[_chooseArray objectAtIndex:section];
    NSString *string=[dic.allKeys objectAtIndex:index];
    NSArray *array=[dic.allValues objectAtIndex:index];
    NSString *title=[array objectAtIndex:titleindex];
    
    NSLog(@"%@-%@",string,title);
    

}

#pragma mark -- dropdownList DataSource
-(NSInteger)numberOfSections
{
    return [_chooseArray count];
}
-(NSInteger)numberOfRowsInSection:(NSInteger)section
{
    NSMutableArray *array =_chooseArray[section];
    return array.count;
}
- (NSInteger)numberOfRowsInSection:(NSInteger)section index:(NSInteger)index
{
    NSMutableArray *array =_chooseArray[section];
    NSArray *indexArray=[array[index] allValues][0];
    return indexArray.count;
}
- (BOOL)titleIndexSectionIsBeingWithSection:(NSInteger)section
{
    if (section==2) {
        return YES;
    }else
    {
        return NO;
    }
}
-(NSString *)titleInSection:(NSInteger)section index:(NSInteger) index
{
    NSMutableArray *array =_chooseArray[section];
    NSString *indexKey=[array[index] allKeys][0];
    return indexKey;
}
- (NSString *)titleInSection:(NSInteger)section index:(NSInteger)index titleIndex:(NSInteger)titleindex
{
    NSMutableArray *array =_chooseArray[section];
    NSArray *indexArray=[array[index] allValues][0];
    return indexArray[titleindex];
}
//默认返回第几行
-(NSInteger)defaultShowSection:(NSInteger)section
{
    if (section==0) {
        return 2;
    }else
    {
        return 0;
    }
}
- (NSInteger)defaultShowSection:(NSInteger)section index:(NSInteger)index
{
    if (section==0 && index==2) {
        return 0;
    }else
    {
        return 1;
    }
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
